/***************************
新增or编辑
* */
<template>
  <el-dialog
    :title="dialogTitle"
    :close-on-click-modal="false"
    :visible.sync="visible"
    top="8vh"
    @close="closeDialog()"
    width="40vw"
  >
    <div class="boxsty">
      <el-form
        ref="dataForm"
        :rules="formRules"
        :model="dataForm"
        label-width="100px"
        @keyup.enter.native="dataFormSubmit()"
      >
        <el-row>
          <el-form-item label="统计名称:" prop="tjmc">
            <el-input v-model="dataForm.tjmc" placeholder="统计名称" ></el-input>
          </el-form-item>
        </el-row>


        <el-form-item  label="规则名称:" prop="ajszb" >
          <el-input type="text" v-model="dataForm.ajszb" placeholder="规则名称1"  max-length="10"></el-input>
        </el-form-item>
        <el-form-item  prop="aszb">
          <el-input type="text" v-model="dataForm.aszb" placeholder="规则名称2"  max-length="10"></el-input>
        </el-form-item>
        <el-form-item  prop="bszb">
          <el-input type="text" v-model="dataForm.bszb" placeholder="规则名称3"  max-length="10"></el-input>
        </el-form-item>
        <el-form-item  prop="cszb">
          <el-input type="text" v-model="dataForm.cszb" placeholder="规则名称4"  max-length="10"></el-input>
        </el-form-item>
        <el-form-item  prop="dszb">
          <el-input type="text" v-model="dataForm.dszb" placeholder="规则名称5"  max-length="10"></el-input>
        </el-form-item>
        <el-form-item  prop="eszb">
          <el-input type="text" v-model="dataForm.eszb" placeholder="规则名称6"  max-length="10"></el-input>
        </el-form-item>
        <el-form-item  prop="fszb">
          <el-input type="text" v-model="dataForm.fszb" placeholder="规则名称7"  max-length="10"></el-input>
        </el-form-item>
        <el-form-item>
          <span style="color:red"> 系统内奖金模块使用评价等级为A/B/C/D。</span>
        </el-form-item>
        <el-form-item label="备注:" prop="bz">
          <el-input type="textarea" :rows="4" v-model="dataForm.bz" placeholder="备注"  max-length="10"></el-input>
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" plain @click="closeDialog()">返回</el-button>
      <el-button type="primary" plain @click="handleConfirm">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
// 接口 api
import {
    addAssess,
    updateAssess

} from "@/api/statisticsanalysis/assessApi.js";
export default {
  data() {
    return {
      dialogTitle: "新增",
      visible: false,
      dataForm: {
        tjmc: "",
        ajszb:"A",
        aszb:"B",
        bszb:"C",
        cszb:"D",
        dszb:"E",
        eszb:"F",
        fszb:"G",
      },
      formRules: {
        tjmc: [{ required: true, message: "请输入统计名称", trigger: "blur" }],
        bz: [{ required: true, message: "请输入备注", trigger: "blur" }],
        ajszb: [{ required: true, message: "请输入规则名称1", trigger: "blur" }],
        aszb: [{ required: true, message: "请输入规则名称2", trigger: "blur" }],
        bszb: [{ required: true, message: "请输入规则名称3", trigger: "blur" }],
        cszb: [{ required: true, message: "请输入规则名称4", trigger: "blur" }],
        dszb: [{ required: true, message: "请输入规则名称5", trigger: "blur" }],
        eszb: [{ required: true, message: "请输入规则名称6", trigger: "blur" }],
        fszb: [{ required: true, message: "请输入规则名称7", trigger: "blur" }],

      },

    };
  },
  created() {
  },
  methods: {

    // 初始化
    init(data) {
      if (data != undefined) {
        this.dataForm = data;
        this.dialogTitle = "编辑";
      } else {

      }
      this.visible = true;
    },
    // 确定
    handleConfirm() {
        this.$refs.dataForm.validate(valid => {
            if (valid) {
                if (this.dataForm.id) {
                    updateAssess(Object.assign(this.dataForm))
                        .then(r => {
                            if (r.data.code == 0) {
                                this.$message.success("编辑成功");
                                this.$emit("refreshDataList");
                                this.closeDialog();
                            } else {
                                this.$message.error(r.data.msg);
                            }
                        })
                        .catch(err => {});
                } else {
                    addAssess(Object.assign(this.dataForm))
                        .then(r => {
                            if (r.data.code == 0) {
                                this.$message.success("新增成功");
                                this.$emit("refreshDataList");
                                this.closeDialog();
                            } else {
                                this.$message.error(r.data.msg);
                            }
                        })
                        .catch(err => {});
                }
            } else {
                console.log("error submit!!");
                return false;
            }
        });
    },
    // 表单提交
    dataFormSubmit() {},
    // 关闭
    closeDialog() {
      this.visible = false;
      this.$emit("closeDialog");
    }
  }
};
</script>

<style>
</style>
